using System;
using FireStarter.Base;
using FireStarter.CodeGeneration;
using FireStarterModeller.BO;
using FireStarterModeller.Test;
using Habanero.Util;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration
{
    //TODO: redo random string generation so you can have any length
    //TODO: datetime min/max - have to make sure user provides a useful format in the min/max prop box (use a DTpicker?)
    //TODO: string pattern match problem (dictionary attack? or force developer to provide sample values)
    //TODO: 1-to-1 relationships (will get a circular call)

    [TestFixture]
    public class TestValidValueGenerator : TestBase
    {
        private static DMProperty GetDmProperty(string assemblyName, string typeName)
        {
            
            DMSolution dmSolution = new DMSolution();
            dmSolution.PropertyTypes.Add(TestUtilsDMPropertyType.CreateDMProperty(assemblyName, typeName));
            DMAssembly dmAssembly = new DMAssembly();
            dmAssembly.Solution = dmSolution;
            DMClass dmClass = TestUtilsDMClass.CreateUnsavedValidDMClass();
            dmClass.Assembly = dmAssembly;
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
            dmProperty.Class = dmClass;
            dmProperty.PropertyTypeString = assemblyName + "." + typeName;
            return dmProperty;
        }

        [Test]
        public void Test_ValidValue_String()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "String");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.String", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_Char()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Char");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Char", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("TestUtilsShared.GetRandomString()[0]", validValue);
        }

        [Test]
        public void Test_ValidValue_Int32()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int32");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Int32", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_Int64()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int64");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Int64", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("(long)TestUtilsCodeGen.GetRandomInt()", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_UInt32()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "UInt32");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.UInt32", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("(uint)TestUtilsCodeGen.GetRandomInt()", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_UInt64()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "UInt64");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.UInt64", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("(ulong)TestUtilsCodeGen.GetRandomInt()", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_Int16()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int16");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Int16", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("(short)TestUtilsCodeGen.GetRandomInt(30000)", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_UInt16()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "UInt16");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.UInt16", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("(ushort)TestUtilsCodeGen.GetRandomInt(30000)", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_Byte()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Byte");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Byte", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("(byte)TestUtilsCodeGen.GetRandomInt(255)", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_SByte()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "SByte");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.SByte", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("(sbyte)TestUtilsShared.GetRandomInt(127)", validValue);
        }

        [Test]
        public void Test_ValidValue_Decimal()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Decimal");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Decimal", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Test]
        public void Test_ValidValue_Double()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Double");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Double", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Test]
        public void Test_ValidValue_Float()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Single");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Single", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Test]
        public void Test_ValidValue_Boolean()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Boolean");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Boolean", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        private enum MyEnum
        {
            Value1,
            Value2,
            Value3
        }

        [Test]
        public void Test_ValidValue_Enum()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("FireStarter.Test.CodeGeneration", "TestValidValueGenerator.MyEnum");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("FireStarter.Test.CodeGeneration.TestValidValueGenerator.MyEnum", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Test]
        public void Test_ValidValue_Guid()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Guid");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Guid", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Test]
        public void Test_ValidValue_DateTime()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "DateTime");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.DateTime", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_Object()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Object");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Object", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("TestUtilsShared.GetRandomString()", validValue);
        }

        [Test]
        public void Test_ValidValue_IntWithMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int32");
            dmProperty.DefaultPropRule = null;
            AddPropRule(dmProperty, "max", "100");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Int32", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Test]
        public void Test_ValidValue_IntWithMin_AddsMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int32");
            dmProperty.DefaultPropRule = null;
            AddPropRule(dmProperty, "min", "10");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Int32", dmProperty.PropertyTypeString);

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        private void AddPropRule(DMProperty modelProperty, string key, string value)
        {
            DMPropRule propRule = new DMPropRule();
            propRule.DMProperty = modelProperty;
            DMPropRuleParameter propRuleParameter = new DMPropRuleParameter();
            propRuleParameter.KeyName = key;
            propRuleParameter.Value = value;
            propRuleParameter.PropRule = propRule;
            modelProperty.DefaultPropRule = propRule;
        }

        [Test]
        public void Test_ValidValue_StringWithMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "String");
            dmProperty.DefaultPropRule = null;
            AddPropRule(dmProperty, "maxLength", "1000");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.String", dmProperty.PropertyTypeString);
            //Assert.AreEqual(1, dmProperty.PropRules.Count);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Test]
        public void Test_ValidValue_StringWithMinMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "String");
            dmProperty.DefaultPropRule = null;
//            dmProperty.PropRules.Remove(dmProperty.PropRules[0]);
            DMPropRule propRule = new DMPropRule();
            AddpropRuleParameter(propRule, "maxLength", "1000");
            AddpropRuleParameter(propRule, "minLength", "10");
            dmProperty.DefaultPropRule = propRule;
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.String", dmProperty.PropertyTypeString);
//            Assert.AreEqual(2, dmProperty.PropRules.Count);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        private static void AddpropRuleParameter(DMPropRule propRule, string key, string value)
        {
            DMPropRuleParameter dmPropRuleParameter = propRule.PropRuleParameters.CreateBusinessObject();
            dmPropRuleParameter.KeyName = key;
            dmPropRuleParameter.Value = value;
        }

        [Test]
        public void Test_ValidValue_IntWithMinMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int32");
            dmProperty.DefaultPropRule = null;
            DMPropRule propRule = new DMPropRule();
            AddpropRuleParameter(propRule, "max", "1000");
            AddpropRuleParameter(propRule, "min", "10");
            dmProperty.DefaultPropRule = propRule;
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Int32", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", validValue);
        }

        [Ignore("Currently dont support this datatype in Firestarter")] //TODO Brett 02 Apr 2009: Currently dont support this datatype in Firestarter
        [Test]
        public void Test_ValidValue_ShortWithMinMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int16");
            dmProperty.DefaultPropRule = null;
//            dmProperty.PropRules.Remove(dmProperty.PropRules[0]);
            AddPropRule(dmProperty, "max", "1000");
            AddPropRule(dmProperty, "min", "10");
            //---------------Assert Precondition----------------
            Assert.AreEqual("System.Int16", dmProperty.PropertyTypeString);
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);

            //---------------Test Result -----------------------
            Assert.AreEqual("(short)TestUtilsCodeGen.GetRandomInt(10,1000)", validValue);
        }

        [Test]
        public void Test_ValidValue_DateTimeWithMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "DateTime");
            dmProperty.DefaultPropRule = null;
//            dmProperty.PropRules.Remove(dmProperty.PropRules[0]);
            AddPropRule(dmProperty, "max", "2008/01/02");
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);

            //---------------Test Result -----------------------
            Assert.AreEqual
                (string.Format("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", ((IModelProperty)dmProperty).Max), validValue);
        }

        [Test]
        public void Test_ValidValue_DateTimeWithMinMax()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "DateTime");
            dmProperty.DefaultPropRule = null;
            DMPropRule propRule = new DMPropRule();
            AddpropRuleParameter(propRule, "max", "2008/01/02");
            AddpropRuleParameter(propRule, "min", "2008/01/10");
            dmProperty.DefaultPropRule = propRule;
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);

            //---------------Test Result -----------------------
            Assert.AreEqual
                (string.Format
                     ("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")", ((IModelProperty)dmProperty).Min,
                      ((IModelProperty) dmProperty).Max), validValue);
        }

        [Test]
        public void Test_ValidValue_SimpleLookupList()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDMPropertyWithSimpleLList("System", "String");

            DMClass dmClass = new DMClass();
            dmClass.ClassNameBO = "TestClass";
            dmProperty.Class = dmClass;
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")",validValue);
        }

        private DMProperty GetDMPropertyWithSimpleLList(string assemblyName, string typeName)
        {
            DMSolution dmSolution = new DMSolution();
            dmSolution.PropertyTypes.Add(TestUtilsDMPropertyType.CreateDMProperty(assemblyName, typeName));
            DMAssembly dmAssembly = new DMAssembly();
            dmAssembly.Solution = dmSolution;
            DMClass dmClass1 = TestUtilsDMClass.CreateUnsavedValidDMClass();
            dmClass1.Assembly = dmAssembly;
            DMProperty dMProperty1 = new DMProperty();
            dMProperty1.LookupList = new DMLookupListSimple();
            TestUtilsDMProperty.SetDMPropTOValidValues(dMProperty1, true);
            DMProperty dMProperty = dMProperty1;
            dMProperty.Class = TestUtilsDMClass.CreateUnsavedValidDMClass();
            dMProperty.PropertyTypeString = DMPropertyType.PROP_TYPE_STRING;
            DMProperty dmProperty1 = dMProperty;
            dmProperty1.Class = dmClass1;
            dmProperty1.PropertyTypeString = assemblyName + "." + typeName;
            DMProperty dmProperty = dmProperty1;
            dmProperty.LookupList = new DMLookupListSimple();
            dmProperty.PropertyName = "TestProperty";
            return dmProperty;
        }

        [Test]
        public void Test_ValidValue_SimpleLookupList_NonString()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDMPropertyWithSimpleLList("System", "Int32");
            dmProperty.PropertyName = "TestProperty";

            DMClass dmClass = new DMClass();
            dmClass.ClassNameBO = "TestClass";
            dmProperty.Class = dmClass;
            string upper = dmProperty.Class.ToString();
            string _className = StringUtilities.ToLowerFirstLetter(upper) + "1";
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual("factory.GetValidPropValue(" + _className + "=>" + _className + "." + dmProperty.PropertyName + ")",validValue);
        }

        [Test, Ignore("TODO 2009-03-30 What are we doing now with the new lookup list format")]
        public void Test_ValidValue_BOLookupList_Guid()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Guid");
            //dmProperty.LookupListType = ModelLookupType.BusinessObject;
            dmProperty.LookupList = new DMLookupListSimple();
            dmProperty.PropertyName = "TestProperty";

            DMClass dmClass = new DMClass();
            dmClass.ClassNameBO = "TestClass";
            dmProperty.Class = dmClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual
                (@"((BusinessObject)GetRandomLookupListValue(testClass.Props[""TestProperty""].PropDef.LookupList.GetLookupList())).ID.GetAsGuid()",
                 validValue);
        }

        [Test, Ignore("TODO 2009-03-30 What are we doing now with the new lookup list format")]
        public void Test_ValidValue_BOLookupList_String()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "String");
            //modelProperty.LookupListType = ModelLookupType.BusinessObject;
            dmProperty.LookupList = new DMLookupListSimple();
            dmProperty.PropertyName = "TestProperty";

            DMClass dmClass = new DMClass();
            dmClass.ClassNameBO = "TestClass";
            dmProperty.Class = dmClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual
                (@"((BusinessObject)GetRandomLookupListValue(testClass.Props[""TestProperty""].PropDef.LookupList.GetLookupList())).ID.GetObjectId()",
                 validValue);
        }

        [Test, Ignore("TODO 2009-03-30 What are we doing now with the new lookup list format")]
        public void Test_ValidValue_BOLookupList_Int()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = GetDmProperty("System", "Int32");
            //modelProperty.LookupListType = ModelLookupType.BusinessObject;
            dmProperty.LookupList = new DMLookupListSimple();
            dmProperty.PropertyName = "TestProperty";

            DMClass dmClass = new DMClass();
            dmClass.ClassNameBO = "TestClass";
            dmProperty.Class = dmClass;
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(dmProperty);
            //---------------Test Result -----------------------
            Assert.AreEqual
                (@"(System.Int32) Convert.ChangeType(((BusinessObject)GetRandomLookupListValue(testClass.Props[""TestProperty""].PropDef.LookupList.GetLookupList())).ID.GetObjectId(),typeof(System.Int32))",
                 validValue);
        }

        [Test,
         Ignore(
             "TODO 2009-03-30 On AllRelationships, need to also clone the RelationshipProperties and write tests for it"
             )]
        public void Test_ValidValue_Relationships_FromChild()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = new DMClass();
            DMProperty parentProp = new DMProperty();
            parentProp.PropertyName = "ParentID";
            parentProp.Class = parentClass;

            DMClass childClass = new DMClass();
            childClass.ClassNameBO = "ChildClass";
            DMProperty childProp = new DMProperty();
            childProp.PropertyName = "ParentIDRenamed";
                //put differently here to make sure we get the parent's prop name, not the child's
            childProp.Class = childClass;

            DMRelationship childToParentRelationship = new DMRelationship();
            childToParentRelationship.Cardinality = Cardinality.Single;
            childToParentRelationship.RelatedClass = parentClass;
            //childToParentRelationship.RelatedAssembly = "Assembly";

            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationshipProperty.OwnerProperty = childProp;
            dmRelationshipProperty.RelatedProperty = parentProp;
            childToParentRelationship.RelationshipProperties.Add(dmRelationshipProperty);

            //childToParentRelationship.Property = childProp;
            //childToParentRelationship.RelatedProperty = parentProp;
            childClass.OwnerRelationships.Add(childToParentRelationship);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(childProp);
            //---------------Test Result -----------------------
            Assert.AreEqual(@"TestUtilsCodeGen.CreateSavedParentClass().ParentID", validValue);
        }

        [Test,
         Ignore(
             "TODO 2009-03-30 On AllRelationships, need to also clone the RelationshipProperties and write tests for it"
             )]
        public void Test_ValidValue_Relationships_ParentPropertyNotInRelationship()
        {
            //---------------Set up test pack-------------------
            DMClass parentClass = new DMClass();
            parentClass.ClassNameBO = "ParentClass";
            DMProperty parentProp = new DMProperty();
            parentProp.PropertyName = "ParentID";
            parentProp.Class = parentClass;

            DMPropertyType dmPropertyType = new DMPropertyType();
            dmPropertyType.PropertyTypeName = "Guid";
            dmPropertyType.AssemblyName = "System";
            parentProp.PropertyType = dmPropertyType;

            DMClass childClass = new DMClass();
            DMProperty childProp = new DMProperty();
            childProp.PropertyName = "ParentIDRenamed"; //put differently here to make sure we get the related prop name
            childProp.Class = childClass;

            DMRelationship parentToChildRelationship = new DMRelationship();
            parentToChildRelationship.Cardinality = Cardinality.Multiple;
            parentToChildRelationship.RelatedClass = childClass;
            //parentToChildRelationship.RelatedAssembly = "Assembly";

            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationshipProperty.OwnerProperty = parentProp;
            dmRelationshipProperty.RelatedProperty = childProp;
            parentToChildRelationship.RelationshipProperties.Add(dmRelationshipProperty);

            parentClass.OwnerRelationships.Add(parentToChildRelationship);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(parentProp);
            //---------------Test Result -----------------------
            Assert.AreEqual(@"Guid.NewGuid()", validValue);
        }

        [Test,
         Ignore(
             "TODO 2009-03-30 On AllRelationships, need to also clone the RelationshipProperties and write tests for it"
             )]
        public void Test_ValidValue_Relationships_WithInheritance()
        {
            //---------------Set up test pack-------------------
            DMAssembly dmAssembly = new DMAssembly();

            DMClass relatedClass = new DMClass();
            DMProperty parentProp = new DMProperty();
            parentProp.PropertyName = "RelatedClassID";
            parentProp.Class = relatedClass;

            DMClass superClass = TestUtilsCodeGen.CreateModelClassOnProject(dmAssembly, "SuperClass");
            DMProperty childProp = TestUtilsCodeGen.CreatePropertyOnClass(superClass, "RelatedClassIDRenamed");
                //put differently here to make sure we get the related prop name

            DMClass childClass = TestUtilsCodeGen.CreateModelClassOnProject(dmAssembly, "ChildClass");

            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            dmInheritanceRelationship.SuperClass = superClass;
            childClass.InheritanceSuperClassRelationship = dmInheritanceRelationship;

            // This reassignment happens in the AllProperties method during generation
            childProp.Class = childClass;

            DMRelationship childToParentRelationship = new DMRelationship();
            childToParentRelationship.Cardinality = Cardinality.Single;
            childToParentRelationship.RelatedClass = relatedClass;

            DMRelationshipProperty dmRelationshipProperty = new DMRelationshipProperty();
            dmRelationshipProperty.OwnerProperty = parentProp;
            dmRelationshipProperty.RelatedProperty = childProp;
            childToParentRelationship.RelationshipProperties.Add(dmRelationshipProperty);

            superClass.OwnerRelationships.Add(childToParentRelationship);
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            string validValue = ValidValueGenerator.GetValidValue(childProp);
            //---------------Test Result -----------------------
            Assert.AreEqual(@"TestUtilsCodeGen.CreateSavedRelatedClass().RelatedClassID", validValue);
        }
    }
}